// 跳跃游戏 二  跳到终点最少次数 覆盖范围 每一次记录next的最大范围

/**
 * @param {number[]} nums
 * @return {number}
 */
var jump = function (nums) {
  let result = 0
  let cur = 0, next = 0

  for (let i = 0; i < nums.length; i++) {
    next = Math.max(i + nums[i], next)
    if (i === cur) {
      if (cur >= nums.length - 1) return result
      result++
      cur = next
    }
  }

  return result
};

console.log(jump([2, 3, 1, 1, 4]));
